package LeetCode.LC14;

import java.util.ArrayList;

/**
 * @author corn
 * @create 2020-07-20-15:00
 */
public class LongestCommonPrefix14 {
    public static void main(String[] args) {
//        String[] strs = {"floar","fly","fls"};
//        String[] strs = {"floar"};
        String[] strs = {"","ff"};
        String s = longestCommonPrefix(strs);
        System.out.println(s);
    }
    public static String longestCommonPrefix(String[] strs) {
        if(strs.length == 0)
            return "";
        String ans = strs[0];
        for(int i =1;i<strs.length;i++) {
            int j=0;
            for(;j<ans.length() && j < strs[i].length();j++) {
                if(ans.charAt(j) != strs[i].charAt(j))
                    break;
            }
            ans = ans.substring(0, j);
            if(ans.equals(""))
                return ans;
        }
        return ans;
    }
}
